import time

from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
              "platformName": "Android",
              "appium:deviceName": "emulator-5554",
              "appium:automationName": "uiautomator2",
              "appium:appPackage": "com.achievo.vipshop",
              "appium:appActivity": ".homepage.activity.MainActivity",
              "appium:noReset": True
            }
        #链接
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待
        self.driver.implicitly_wait(20)
        #初始化
    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    #显示等待
    def find_ele_wind(self,loc):
        ele=WebDriverWait(self.driver,30).until(EC.element_to_be_clickable(loc))
        return ele
    #强制等待
    time.sleep(3)
    #截屏
    def jeiping(self,a):
        ele=self.driver.save_screenshot(a)
        return ele
    #轻敲
    def qingqiao(self,a,b):
        ele=self.driver.tap([(a,b)],300)
        return ele
    #滑动
    def huadong(self,a,b,c,d):
        ele=self.driver.swipe(a,b,c,d,300)
        return ele
    #按键
    def anjian(self,a):
        ele=self.driver.press_keycode(a)
        return ele









